package com.ctgu.rabbitmq.controller;

import com.ctgu.rabbitmq.service.ExchangeService;
import com.ctgu.rabbitmq.service.OrdersService;
import com.ctgu.rabbitmq.service.UsersService;
import com.ctgu.rabbitmq.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @ClassName UserController
 * @Author Alex2
 * @Date 2025/3/7 15:03
 **/
@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UsersService usersService;

    @Autowired
    private OrdersService ordersService;

    /**
     * @ Author: Alex
     * @ Description: 实战案例-购物增加积分-插入用户
     */
    // http://localhost:8080/api/users/insertUser?username=Alex
    @GetMapping("insertUser")
    public ApiResult insertUser(@RequestParam String username) {
        return usersService.insertUser(username);
    }

    /**
     * @ Author: Alex
     * @ Description: 实战案例-购物增加积分-插入订单
     */
    // http://localhost:8080/api/users/insertOrder?name=knife&price=49.99&userId=1
    @GetMapping("insertOrder")
    public ApiResult insertOrder(@RequestParam String name, @RequestParam BigDecimal price, @RequestParam Integer userId) {
        return ordersService.insertOrder(name, price, userId);
    }

    /**
     * @ Author: Alex
     * @ Description: 实战案例-购物增加积分-消费增加积分
     */
    // http://localhost:8080/api/users/payment/1
    @GetMapping("payment/{id}")
    public ApiResult payment(@PathVariable String id) {
        return ordersService.payment(id);
    }
}